import 'package:flutter/material.dart';
import 'package:hello_flutter/flutter_study/ButtonBasic.dart';
import 'package:hello_flutter/flutter_study/ImgAndIcon.dart';
import 'package:hello_flutter/flutter_study/TextBasic.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});
  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  var selectedIndex = 0;

  @override
  Widget build(BuildContext context) {

    var theme = Theme.of(context);

    Widget widget;
    switch(selectedIndex){
      case 0:
        widget = const TextBasic();
        break;
      case 1:
        widget = const ButtonBasic();
        break;
      case 2:
        widget = const ImgAndIcon();
        break;
      case 3:
        widget = const ImgAndIcon();
        break;
      default:
        throw UnimplementedError("No widget from index $selectedIndex.");
    }


    return LayoutBuilder(
      builder: (context,constraints) {
        return Scaffold(
          appBar: AppBar(
            backgroundColor: Theme
                .of(context)
                .colorScheme
                .inversePrimary,
            title: const Text("Flutter Container"),
          ),
          body:Row(
            children: [
              SafeArea(child: NavigationRail(
                  extended: constraints.maxWidth >= 600,
                  destinations: const [
                    NavigationRailDestination(icon: Icon(Icons.favorite), label: Text("文本及样式",style: TextStyle(fontWeight: FontWeight.bold,color: Colors.lightBlue,fontSize: 18),)),
                    NavigationRailDestination(icon: Icon(Icons.favorite), label: Text("按钮",style: TextStyle(fontWeight: FontWeight.bold,color: Colors.lightBlue,fontSize: 18),)),
                    NavigationRailDestination(icon: Icon(Icons.favorite), label: Text("图片及Icon",style: TextStyle(fontWeight: FontWeight.bold,color: Colors.lightBlue,fontSize: 18),)),
                    NavigationRailDestination(icon: Icon(Icons.favorite), label: Text("单选开关和复选框",style: TextStyle(fontWeight: FontWeight.bold,color: Colors.lightBlue,fontSize: 18),)),
                  ],
                  selectedIndex: selectedIndex,
                  onDestinationSelected: (value){
                    setState(() {
                      selectedIndex = value;
                    });
                  },
                ),
              ),
              Expanded(child: Container(
                color: theme.colorScheme.primaryContainer,
                child: widget,
              ))
            ],
          ),
        );
      }
    );
  }
}
